import java.io.IOException;
import java.io.RandomAccessFile;


public class RandomAccessFileDemo {

	public static long readLeUnsigned(RandomAccessFile f) throws IOException {
		return (long) f.readUnsignedByte() | (long) f.readUnsignedByte() << 8
				| (long) f.readUnsignedByte() << 16
				| (long) f.readUnsignedByte() << 24;
	}
	
	public static void main(String[] args) throws IOException{
		/*
		 * 0 local file header signature 4 bytes (0x04034b50) 2 version needed
		 * to extract 2 bytes 4 general purpose bit flag 2 bytes 6 compression
		 * method 2 bytes 8 last mod file time 2 bytes 10 last mod file date 2
		 * bytes 12 crc-32 4 bytes 16 compressed size 4 bytes 20 uncompressed
		 * size 4 bytes file name length 2 bytes extra field length 2 bytes
		 */
		// 0x504b0304
		RandomAccessFile raf = new RandomAccessFile("test.zip", "r");
		long magic = readLeUnsigned(raf);
		System.out.format("magic: %x%n", magic);
		if (magic != 0x04034b50) {
			throw new IOException("Bad zip file!");
		}
		raf.seek(16);
		long compressed = readLeUnsigned(raf);
		long uncompressed = readLeUnsigned(raf);
		System.out.format("%d -> %d%n", uncompressed, compressed);
		raf.close();

	}

}
